1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| | ID | DA | | --- | --- | | 使用 keep-alive |  | | 不使用 keep-alive |  | ```vue <div id="example"> <button @click="methodsAll">Go</button> <keep-alive> <component v-bind:is="componentView"></component> </keep-alive> </div> <script> var one = { template: ` <input type="text"> ` }; var two = { template: ` <div>two Template</div> ` }; var three = { template: ` <div>three Template</div> ` }; new Vue({ el: '#example', components: { one, two, three, }, data:{ index:0, list:['one','two','three'], }, computed:{ componentView(){ return this.list[this.index]; } }, methods:{ methodsAll(){ this.index = (++this.index)%3; } } }) </script>
|